package com.globopt.global.algorithm.functions;

import com.globopt.global.algorithm.Function;
import com.globopt.global.algorithm.Point;

/**
 * Sample test function.
 * 
 * @author Richard Gasztany 2012.11.25.
 * 
 */
public class F2 extends Function {
	// Griewank function

	public F2() {
		this.nvars = 2;
	}

	@Override
	public double evaluation(Point x) {
		double s = 0.0;
		double p = 1.0;

		for (int i = 0; i < nvars; i++) {
			s += x.getCoordinate(i) * x.getCoordinate(i);
			p *= Math.cos(x.getCoordinate(i) / Math.sqrt(i + 1));
		}
		return s / 4000.0 - p + 1.0;
	}
}
